# -*- coding: utf-8 -*-
from django.db import models, connection
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin


from aboutfamily import ENCODING
from aboutfamily.user import AVATAR_HOLDER, AVATAR_STORAGE_PATH

Y_N_Choice = ( 
        ("Y", _("Yes")),
        ("N", _("No")),
        )
#Extends django's User
models.CharField(max_length=1, 
    choices=(("N", _("Normal")),("D", _("Disabled")),("B", _("Banned"))),
    help_text=("User status")).contribute_to_class(User, "status")
    
#Family information
class Family(models.Model):
    family_name = models.CharField(max_length=30, verbose_name=_("Family Name"))
        
    def __unicode__(self):
        return self.family_name  

#An user's profile
class Profile(models.Model):
    GENDER = (
        ("M", _("Male")),
        ("F", _("Female")),
    )
    TYPES = (
        ("I", _("Individual")),
        ("C", _("Company")),
    )
    first_name = models.CharField(max_length=30, verbose_name=_("First name"), blank=True)
    last_name = models.CharField(max_length=30, verbose_name=_("Last name"), blank=True)
    type = models.CharField(max_length=1, choices=TYPES, verbose_name=_("Profile Type"), blank=True)
    dob = models.DateField(verbose_name=_("Date of birth"), blank=True, null=True)
    gender = models.CharField(max_length=1, choices=GENDER, verbose_name=_("Gender"), blank=True)
    address = models.CharField(max_length=255, verbose_name=_("Address"), blank=True)
    city = models.CharField(max_length=30, verbose_name=_("City"), blank=True)
    country = models.CharField(max_length=30, verbose_name=_("Country"), blank=True)
    avatar = models.ImageField(_('Avator'), upload_to=AVATAR_STORAGE_PATH, blank=True)    
    family = models.ForeignKey(Family, blank=True, null=True)
    family_initiator = models.CharField(max_length=1,choices=Y_N_Choice,blank=True)
    #Relation with family's initiator
    Relation = models.CharField(max_length=12)
    user = models.OneToOneField(User)
    
    
    
    def __str__(self):
        return self.first_name + " " + self.last_name
    
    @classmethod
    def get_new_profile(cls, user):
        return Profile(user=user, avatar=AVATAR_HOLDER)
    

